package com.cysnake.easyyi.activity;

import java.util.ArrayList;

import com.cysnake.easyyi.R;
import com.cysnake.easyyi.Dao.GuaciDao;
import com.cysnake.easyyi.vo.GuaVO;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ScanGuaciActivity extends Activity {

	ListView scanListView;
	GuaciDao guaciDao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.scanguaci);
		modify();
	}

	private void modify() {
		scanListView = (ListView) findViewById(R.id.scan_listview);
		guaciDao = new GuaciDao(this);
		guaciDao = guaciDao.open();
		ArrayList<String> list = guaciDao.getAllName();
		guaciDao.close();
		scanListView.setAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_expandable_list_item_1, list));
		
		scanListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				ListView list = (ListView) parent;
				String name = (String) list.getItemAtPosition(position);
				Log.i("test", name);
				Intent intent = new Intent(ScanGuaciActivity.this,
						GuaInfoActivity.class);
				intent.putExtra("name", name);
				startActivity(intent);

			}
		});
	}
}
